package cn.dengqiang.org.controller;

import cn.dengqiang.basic.util.AjaxResult;
import cn.dengqiang.basic.util.PageList;
import cn.dengqiang.org.domain.SystemDictionarytype;
import cn.dengqiang.org.query.SystemDictionarytypeQuery;
import cn.dengqiang.org.service.ISystemDictionarytypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController   //=@ResponseBody+@Controller
@RequestMapping("/systemDictionarytype")

@Api(tags = "产品接口",description = "产品接口详细描述")
public class SystemDictionarytypeController {

    @Autowired
    private ISystemDictionarytypeService systemDictionarytypeService;

    @PutMapping
    public AjaxResult save(@RequestBody SystemDictionarytype systemDictionarytype){
        try {
            if (systemDictionarytype.getId()==null){
                systemDictionarytypeService.add(systemDictionarytype);
            }else {
                systemDictionarytypeService.update(systemDictionarytype);
            }
            return AjaxResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setMessage("保存失败"+e.getMessage());
        }
    }




    @ApiOperation(value = "删除",notes = "根据id删除一条数据")
    @DeleteMapping("/{id}")
    public AjaxResult del(@PathVariable("id") Long id){
        try {
            systemDictionarytypeService.del(id);
            return new AjaxResult();
        } catch (Exception e) {
            e.printStackTrace();
           return new AjaxResult("删除失败!"+e.getMessage());
       }
    }

    @ApiOperation(value = "查询",notes = "根据id查询一条数据")
    @GetMapping("/{id}") //根据id查询
    public SystemDictionarytype getById(@PathVariable("id") Long id){
        return systemDictionarytypeService.getById(id);
    }

    @ApiOperation(value = "查询",notes = "查询所有信息")
    @GetMapping //systemDictionarytype 查询所有
    public List<SystemDictionarytype> getAll(){
        return systemDictionarytypeService.getAll();
    }

    @ApiOperation(value = "查询",notes = "分页查询")
    @PostMapping//分页查询
    public PageList<SystemDictionarytype> list(@RequestBody SystemDictionarytypeQuery query){
        return systemDictionarytypeService.queryPage(query);
    }


    @PatchMapping
    public AjaxResult batchDel(@RequestBody List<Long> ids){
        try {
            systemDictionarytypeService.batchDel(ids);
            return AjaxResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setMessage("批量删除失败"+e.getMessage());
        }

    }


}
